
function renewIns(recordID)
{
	if(!/^[1-9]\d*$/.test(recordID))
	{
		alert("information is illegal！！！");
		return;
	}
	var days = document.getElementById("days").value;
	if(""!=days)
	{
		if(!/^([1-9]|[1-9]\d|100)$/.test(days))
		{
			alert("oops,the range of days is from 1 - 100");
			return;
		}
	}else
	{
		days = document.getElementById("selectdays").value;
	}
	var xmlHttp = null;
	if(window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}else
	{
		alert("Ajax won't show in your web browser ");
		return;
	}

	xmlHttp.open("GET", "RenewServlet?recordID=" + recordID +"&option=renew&days=" + days, true);
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			var login=/<script>/ig;
			if(login.test(xmlHttp.responseText))
			{
				eval("top.location.href='/lab/login.jsp'");
				return;
			}
			var contentType = xmlHttp.getResponseHeader("Content-Type");
			if(contentType == "text/html")
			{
				var message = xmlHttp.responseText;
				document.getElementById("message").innerHTML= message;
				document.getElementById("firstname").value = "";
				document.getElementById("lastname").value =  "";
				document.getElementById("gender").value = "";
				document.getElementById("email").value = "";
				document.getElementById("renewBody").innerHTML = 
				
				"<table width='100%' height='35' border='1' cellpadding='0'cellspacing='0' bordercolor='#8D8D8D' bgcolor='#FFFFFF'>"+
				"<tr align='center' bgcolor='#e3F4F7'>"+
					"<td width='24%' height='25' bgcolor='#F9D16B'>Instrument name</td>"+
					"<td width='12%' bgcolor='#F9D16B'>Barcode</td>"+
					"<td width='12%' bgcolor='#F9D16B'>Borrow time</td>"+
					"<td width='13%' bgcolor='#F9D16B'>Back time</td>"+
					"<td width='12%' bgcolor='#F9D16B'>option</td>"+
				"</tr>"+
				"<tbody>"+
				"<tr>"+
				"	<td height='25' style='padding: 5px;'>&nbsp;</td>" +
				"	<td style='padding: 5px;'>&nbsp</td>" +
				"	<td style='padding: 5px;'>&nbsp</td>" +
				"	<td align='center'>&nbsp</td>" +
				"	<td width='12%' align='center'>&nbsp</td>" +
				"</tr>"+
				"</tbody>"+
				"</table>";
			}
			else if(contentType == "application/json")
			{
				var jsonObj = eval('('+xmlHttp.responseText+')');
				document.getElementById("userid").value = jsonObj.userID;
				document.getElementById("firstname").value = jsonObj.firstname;
				document.getElementById("lastname").value = jsonObj.lastname;
				document.getElementById("gender").value = jsonObj.gender;
				document.getElementById("email").value = jsonObj.email;
				document.getElementById("days").value = jsonObj.days;
				
				document.getElementById("renewBody").innerHTML = 
					"<table width='100%' height='35' border='1' cellpadding='0'cellspacing='0' bordercolor='#8D8D8D' bgcolor='#FFFFFF'>"+
					"<tr align='center' bgcolor='#e3F4F7'>"+
						"<td width='24%' height='25' bgcolor='#F9D16B'>Instrument name</td>"+
						"<td width='12%' bgcolor='#F9D16B'>Barcode</td>"+
						"<td width='12%' bgcolor='#F9D16B'>Borrow time</td>"+
						"<td width='13%' bgcolor='#F9D16B'>Back time</td>"+
						"<td width='12%' bgcolor='#F9D16B'>option</td>"+
					"</tr>"+
					"<tbody>"+
					"<tr>"+
                    "       <td align='center' height='25' style='padding: 5px;'>"+jsonObj.insName+"</td>" +
                    "       <td align='center' style='padding: 5px;'>"+jsonObj.barcode+"</td>" +
                    "       <td align='center' style='padding: 5px;'>"+jsonObj.borrowDate+"</td>" +
                    "       <td align='center'>"+jsonObj.SBackDate+"</td>" +
                    "       <td width='12%' align='center'>&nbsp</td>" +
                    "</tr>"
					"</tbody>"+
					"</table>";
				
				document.getElementById("message").innerHTML = "SUCCESS!";
			}
		}
		else
		{
			document.getElementById("message").innerHTML = "doing...";
		}
	}
	xmlHttp.send(null);
}
function getRenewInfo()
{
	var userID = document.getElementById("userid").value;
	if(userID=="")
	{alert("please enter the userid!");return false;}
	if(!/^\d+$/.test(userID))
	{alert("userid is invalid!");return false;}
	if(userID.length!=8)
	{alert("length of userid is invalid!");return false;}
	
	
	var xmlHttp = null;
	if(window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}else
	{
		alert("Ajax won't show in your web browser ");
		return;
	}

	xmlHttp.open("GET", "RenewServlet?userID="+ userID +"&option=checkr", true);
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			var login=/<script>/ig;
			if(login.test(xmlHttp.responseText))
			{
				eval("top.location.href='/lab/login.jsp'");
				return;
			}
			var contentType = xmlHttp.getResponseHeader("Content-Type");
			if(contentType == "text/html")
			{
				var message = xmlHttp.responseText;
				document.getElementById("message").innerHTML= message;
				document.getElementById("firstname").value = "";
				document.getElementById("lastname").value =  "";
				document.getElementById("gender").value = "";
				document.getElementById("email").value = "";
				document.getElementById("renewBody").innerHTML = 
					"<table width='100%' height='35' border='1' cellpadding='0'cellspacing='0' bordercolor='#8D8D8D' bgcolor='#FFFFFF'>"+
					"<tr align='center' bgcolor='#e3F4F7'>"+
						"<td width='24%' height='25' bgcolor='#F9D16B'>Instrument name</td>"+
						"<td width='12%' bgcolor='#F9D16B'>Barcode</td>"+
						"<td width='12%' bgcolor='#F9D16B'>Borrow time</td>"+
						"<td width='13%' bgcolor='#F9D16B'>Back time</td>"+
						"<td width='12%' bgcolor='#F9D16B'>option</td>"+
					"</tr>"+
					"<tbody>"+
					"<tr>"+
					"	<td height='25' style='padding: 5px;'>&nbsp;</td>" +
					"	<td style='padding: 5px;'>&nbsp</td>" +
					"	<td style='padding: 5px;'>&nbsp</td>" +
					"	<td align='center'>&nbsp</td>" +
					"	<td width='12%' align='center'>&nbsp</td>" +
					"</tr>"+
					"</tbody>"+
					"</table>";
				
			}else if(contentType == "application/json")
			{
				var jsonArray = eval('(' + xmlHttp.responseText +')');
				
				document.getElementById("userid").value = jsonArray[0].userID;
				document.getElementById("firstname").value = jsonArray[0].firstname;
				document.getElementById("lastname").value = jsonArray[0].lastname;
				document.getElementById("gender").value = jsonArray[0].gender;
				document.getElementById("email").value = jsonArray[0].email;
				//document.getElementById("days").value = jsonArray[0].days;
				
				var trs = 
				"<table width='100%' height='35' border='1' cellpadding='0'cellspacing='0' bordercolor='#8D8D8D' bgcolor='#FFFFFF'>"+
				"<tr align='center' bgcolor='#e3F4F7'>"+
				"<td width='24%' height='25' bgcolor='#F9D16B'>Instrument name</td>"+
				"<td width='12%' bgcolor='#F9D16B'>Barcode</td>"+
				"<td width='12%' bgcolor='#F9D16B'>Borrow time</td>"+
				"<td width='13%' bgcolor='#F9D16B'>Back time</td>"+
				"<td width='12%' bgcolor='#F9D16B'>option</td>"+
				"</tr>";
				for(var i = 0; i < jsonArray.length; i++)
				{
					var jsonObj = jsonArray[i];
					trs = trs +
					"<tr>"+
					"	<td align='center' height='25' style='padding: 5px;'>"+jsonObj.insName+"</td>" +
					"	<td align='center' style='padding: 5px;'>"+jsonObj.barcode+"</td>" +
					"	<td align='center' style='padding: 5px;'>"+jsonObj.borrowDate+"</td>" +
					"	<td align='center'>"+jsonObj.SBackDate+"</td>" +
					"	<td width='12%' align='center'>" +
					"	<a href='#' onclick='renewIns("+ jsonObj.recordID +");return false;'><font size='3'>Renew</font></a></td>" +
					"</tr>";
					
				}
				trs = trs+"</table>";
				document.getElementById("renewBody").innerHTML = trs;
				document.getElementById("message").innerHTML = "SUCCESS!";
			}
		}
		else
		{
			document.getElementById("message").innerHTML= "loading...";
		}
	}
	xmlHttp.send(null);

}